﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="../src/utilFn.js"></script>
    <script src="../utilPackage/jquery-1.11.3.min.js"></script>
    <link href="../utilPackage/utilFn.css" rel="stylesheet" />
</head>
<body>
    <div class="subPage">
        <div class="subPage-title">
         数字类型数组常用处理方法
        </div>
        <div class="subPage-sub-title"></div>
        <div id="min2max" class="subPage-part">
            <div class="subPage-part-title"><span class="title-name">g.<strong>min2max</strong> </span> <span class="title-type">Function(Array)</span> </div>
            <div class="subPage-part-code">
                <pre class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><code class="lang-javascript"></code></li><li class="L1"><code class="lang-javascript"><span class="pln">                    </span><span class="com">//*------数字数组由小到大排序 --------*/ </span></code></li><li class="L2"><code class="lang-javascript"><span class="pln">                     </span><span class="com">//例如：  </span></code></li><li class="L3"><code class="lang-javascript"><span class="pln">                    </span><span class="kwd">var</span><span class="pln"> numAry1 </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[</span><span class="lit">3</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</span><span class="pun">,</span><span class="pln"> </span><span class="lit">4</span><span class="pun">,</span><span class="pln"> </span><span class="lit">8</span><span class="pun">];</span></code></li><li class="L4"><code class="lang-javascript"><span class="pln">                    </span><span class="kwd">var</span><span class="pln"> numAry2 </span><span class="pun">=</span><span class="pln"> g</span><span class="pun">.</span><span class="pln">min2max</span><span class="pun">(</span><span class="pln">numAry1</span><span class="pun">);</span></code></li><li class="L5"><code class="lang-javascript"><span class="pln">                     </span><span class="com">//numAry1就是'[8,6,4,3,2]'; </span></code></li><li class="L6"><code class="lang-javascript"><span class="pln">                     </span><span class="com">//numAry2就是'[8,6,4,3,2]';</span></code></li></ol></pre>
            </div>
            <div class="subPage-part-explain">
                <tt>
                    g.min2max(Array)//将数组从小到大排列<br />                
                </tt>
            </div>
            <div class="subPage-part-explain">
                <div><b>测试方法</b></div>
                <div>
                    请输入对象字符串<b>[Array]</b>（对象中用JSON.parse(String)）
                </div>            
                <div>
                    <textarea id="min2maxInput" class="InputTextarea">[3,2,6,4,8]</textarea>
                </div>        
                <div> <input id="min2maxButton" type="button" value="执行  g.min2max(Array)" /> </div>
                <div>
                    显示结果 (<b>原数组</b>)<span class="font-red">（原数组会改变）</span>
                </div>
                <div>
                    <textarea id="min2maxOutput" class="OutputTextarea"></textarea>
                </div>
                <div>
                    显示结果 (返回的对象)
                </div>
                <div>
                    <textarea id="min2maxOutput1" class="OutputTextarea"></textarea>
                </div>
                <script>
                    $("#min2maxButton").click(function () {
                        var numAry1 = JSON.parse($('#min2maxInput').val());                
                        var numAry2 = g.min2max(numAry1);
                        $('#min2maxOutput').val(JSON.stringify(numAry1));
                        $('#min2maxOutput1').val(JSON.stringify(numAry2));
                    });
                </script>
            </div>
        </div>
        
        <div id="max2min" class="subPage-part">
            <div class="subPage-part-title"><span class="title-name">g.<strong>max2min</strong> </span> <span class="title-type">Function(Array)</span> </div>
            <div class="subPage-part-code">
                <pre class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><code class="lang-javascript"></code></li><li class="L1"><code class="lang-javascript"><span class="pln">                       </span><span class="com">//*------数字数组由大到小排序 --------*/ </span></code></li><li class="L2"><code class="lang-javascript"><span class="pln">                     </span><span class="com">//例如： </span></code></li><li class="L3"><code class="lang-javascript"><span class="pln">                    </span><span class="kwd">var</span><span class="pln"> numAry1 </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[</span><span class="lit">3</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</span><span class="pun">,</span><span class="pln"> </span><span class="lit">4</span><span class="pun">,</span><span class="pln"> </span><span class="lit">8</span><span class="pun">];</span></code></li><li class="L4"><code class="lang-javascript"><span class="pln">                    </span><span class="kwd">var</span><span class="pln"> numAry2 </span><span class="pun">=</span><span class="pln"> g</span><span class="pun">.</span><span class="pln">max2min</span><span class="pun">(</span><span class="pln">numAry1</span><span class="pun">);</span></code></li><li class="L5"><code class="lang-javascript"><span class="pln">                     </span><span class="com">//numAry1就是'[2,3,4,6,8]'; </span></code></li><li class="L6"><code class="lang-javascript"><span class="pln">                     </span><span class="com">//numAry2就是'[2,3,4,6,8]';</span></code></li></ol></pre>
            </div>
            <div class="subPage-part-explain">
                <tt>
                    g.max2min(Array)//将数组从小到大排列<br />                 
                </tt>
            </div>
            <div class="subPage-part-explain">
                <div><b>测试方法</b></div>
                <div>
                    请输入对象字符串<b>[Array]</b>（对象中用JSON.parse(String)）
                </div>             
                <div>
                    <textarea id="max2minInput" class="InputTextarea">[3,2,6,4,8]</textarea>
                </div>
                <div> <input id="max2minButton" type="button" value="执行  g.max2min(Array)" /> </div>
                <div>
                    显示结果 (<b>原数组</b>)<span class="font-red">（原数组会改变）</span>
                </div>
                <div>
                    <textarea id="max2minOutput" class="OutputTextarea"></textarea>
                </div>
                <div>
                    显示结果 (返回的对象)
                </div>
                <div>
                    <textarea id="max2minOutput1" class="OutputTextarea"></textarea>
                </div>
                <script>
                    $("#max2minButton").click(function () {
                        var numAry1 = JSON.parse($('#max2minInput').val());
                        var numAry2 = g.max2min(numAry1);
                        $('#max2minOutput').val(JSON.stringify(numAry1));
                        $('#max2minOutput1').val(JSON.stringify(numAry2));
                    });
                </script>
            </div>
        </div>

        <div id="index" class="subPage-part">
            <div class="subPage-part-title"><span class="title-name">g.<strong>index</strong> </span> <span class="title-type">Function(Array,Value)</span> </div>
            <div class="subPage-part-code">
                <pre class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><code class="lang-javascript"></code></li><li class="L1"><code class="lang-javascript"><span class="pln">                      </span><span class="com">//*------数字数组中某个值的索引位置 --------*/ </span></code></li><li class="L2"><code class="lang-javascript"><span class="pln">                     </span><span class="com">//例如： </span></code></li><li class="L3"><code class="lang-javascript"><span class="pln">                    </span><span class="kwd">var</span><span class="pln"> numAry1 </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[</span><span class="lit">3</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</span><span class="pun">,</span><span class="pln"> </span><span class="lit">4</span><span class="pun">,</span><span class="pln"> </span><span class="lit">8</span><span class="pun">];</span></code></li><li class="L4"><code class="lang-javascript"><span class="pln">                    </span><span class="kwd">var</span><span class="pln"> numAry2 </span><span class="pun">=</span><span class="pln"> g</span><span class="pun">.</span><span class="pln">index</span><span class="pun">(</span><span class="pln">numAry1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</span><span class="pun">);</span></code></li><li class="L5"><code class="lang-javascript"><span class="pln">                     </span><span class="com">//numAry2就是'2'; </span></code></li><li class="L6"><code class="lang-javascript"><span class="pln">                     </span><span class="com">//6在数组里第二位，位置是从0开始</span></code></li></ol></pre>
            </div>
            <div class="subPage-part-explain">
                <tt>
                    g.index(Array,Value)//获取数字在数组中的索引位置<br />                 
                </tt>
            </div>
            <div class="subPage-part-explain">
                <div><b>测试方法</b></div>
                <div>
                    请输入对象字符串<b>[Array]</b>（对象中用JSON.parse(String)）
                </div>
                <div>
                    <textarea id="indexInput" class="InputTextarea">[3,2,6,4,8]</textarea>
                </div>
                <div style="padding:10px;">参数1<b>[Value]</b>：<input id="indexCanshu1" type="text" value="6" /></div>
                <div> <input id="indexButton" type="button" value="执行  g.index(Array,Value))" /> </div>

                <div>
                    显示结果 (返回的对象)
                </div>
                <div>
                    <textarea id="indexOutput" class="OutputTextarea"></textarea>
                </div>
                <script>
                    $("#indexButton").click(function () {
                        var numAry1 = JSON.parse($('#indexInput').val());
                        var canshu1 = parseFloat($('#indexCanshu1').val()) ? parseFloat($('#indexCanshu1').val()):null;
                        var numAry2 = g.index(numAry1,canshu1);
                        $('#indexOutput').val(numAry2);
                    });
                </script>
            </div>
        </div>
       
        <div id="max" class="subPage-part">
            <div class="subPage-part-title"><span class="title-name">g.<strong>max</strong> </span> <span class="title-type">Function(Array)</span> </div>
            <div class="subPage-part-code">
                <pre class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><code class="lang-javascript"></code></li><li class="L1"><code class="lang-javascript"><span class="pln">                     </span><span class="com">//*------数字数组中最大值 --------*/ </span></code></li><li class="L2"><code class="lang-javascript"><span class="pln">                     </span><span class="com">//例如： </span></code></li><li class="L3"><code class="lang-javascript"><span class="pln">                    </span><span class="kwd">var</span><span class="pln"> numAry1 </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[</span><span class="lit">3</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</span><span class="pun">,</span><span class="pln"> </span><span class="lit">4</span><span class="pun">,</span><span class="pln"> </span><span class="lit">8</span><span class="pun">];</span></code></li><li class="L4"><code class="lang-javascript"><span class="pln">                    </span><span class="kwd">var</span><span class="pln"> numAry2 </span><span class="pun">=</span><span class="pln"> g</span><span class="pun">.</span><span class="pln">max</span><span class="pun">(</span><span class="pln">numAry1</span><span class="pun">);</span></code></li><li class="L5"><code class="lang-javascript"><span class="pln">                    console</span><span class="pun">.</span><span class="pln">log</span><span class="pun">(</span><span class="pln">numAry2</span><span class="pun">);</span><span class="pln"> </span><span class="com">//numAry2就是'8';</span></code></li></ol></pre>
            </div>
            <div class="subPage-part-explain">
                <tt>
                    g.max(Array)//获取数组中最大的数<br />                  
                </tt>
            </div>
            <div class="subPage-part-explain">
                <div><b>测试方法</b></div>
                <div>
                    请输入对象字符串<b>[Array]</b>（对象中用JSON.parse(String)）
                </div>
                <div>
                    <textarea id="maxInput" class="InputTextarea">[3,2,6,4,8]</textarea>
                </div>
                <div> <input id="maxButton" type="button" value="执行 g.max(Array)" /> </div>
           
                <div>
                    显示结果 
                </div>
                <div>
                    <textarea id="maxOutput" class="OutputTextarea"></textarea>
                </div>
                <script>
                    $("#maxButton").click(function () {
                        var numAry1 = JSON.parse($('#maxInput').val());
                        var numAry2 = g.max(numAry1);                  
                        $('#maxOutput').val(numAry2);
                    });
                </script>
            </div>
        </div>

        <div id="min" class="subPage-part">
            <div class="subPage-part-title"><span class="title-name">g.<strong>min</strong> </span> <span class="title-type">Function(Array)</span> </div>
            <div class="subPage-part-code">
                <pre class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><code class="lang-javascript"></code></li><li class="L1"><code class="lang-javascript"><span class="pln">                       </span><span class="com">//*------数字数组中最小值 --------*/ </span></code></li><li class="L2"><code class="lang-javascript"><span class="pln">                     </span><span class="com">//例如： </span></code></li><li class="L3"><code class="lang-javascript"><span class="pln">                    </span><span class="kwd">var</span><span class="pln"> numAry1 </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[</span><span class="lit">3</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</span><span class="pun">,</span><span class="pln"> </span><span class="lit">4</span><span class="pun">,</span><span class="pln"> </span><span class="lit">8</span><span class="pun">];</span></code></li><li class="L4"><code class="lang-javascript"><span class="pln">                    </span><span class="kwd">var</span><span class="pln"> numAry2 </span><span class="pun">=</span><span class="pln"> g</span><span class="pun">.</span><span class="pln">min</span><span class="pun">(</span><span class="pln">numAry1</span><span class="pun">);</span></code></li><li class="L5"><code class="lang-javascript"><span class="pln">                    console</span><span class="pun">.</span><span class="pln">log</span><span class="pun">(</span><span class="pln">numAry2</span><span class="pun">);</span><span class="com">//numAry2就是'2';</span></code></li></ol></pre>
            </div>
            <div class="subPage-part-explain">
                <tt>
                    g.min(Array)//获取数组中最小的数<br />                 
                </tt>
            </div>
            <div class="subPage-part-explain">
                <div><b>测试方法</b></div>
                <div>
                    请输入对象字符串<b>[Array]</b>（对象中用JSON.parse(String)）
                </div>
                <div>
                    <textarea id="minInput" class="InputTextarea">[3,2,6,4,8]</textarea>
                </div>
                <div> <input id="minButton" type="button" value="执行  g.min(Array)" /> </div>

                <div>
                    显示结果 
                </div>
                <div>
                    <textarea id="minOutput" class="OutputTextarea"></textarea>
                </div>
                <script>
                    $("#minButton").click(function () {
                        var numAry1 = JSON.parse($('#minInput').val());
                        var numAry2 = g.min(numAry1);
                        $('#minOutput').val(numAry2);
                    });
                </script>
            </div>
        </div>
        
        <div id="sum" class="subPage-part">
            <div class="subPage-part-title"><span class="title-name">g.<strong>sum</strong> </span> <span class="title-type">Function(Array)</span> </div>
            <div class="subPage-part-code">
                <pre class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><code class="lang-javascript"></code></li><li class="L1"><code class="lang-javascript"><span class="pln">                        </span><span class="com">//*------数字数组中数值的总和 --------*/ </span></code></li><li class="L2"><code class="lang-javascript"><span class="pln">                    </span><span class="kwd">var</span><span class="pln"> numAry1 </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[</span><span class="lit">3</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</span><span class="pun">,</span><span class="pln"> </span><span class="lit">4</span><span class="pun">,</span><span class="pln"> </span><span class="lit">8</span><span class="pun">];</span></code></li><li class="L3"><code class="lang-javascript"><span class="pln">                    </span><span class="kwd">var</span><span class="pln"> numAry2 </span><span class="pun">=</span><span class="pln"> g</span><span class="pun">.</span><span class="pln">sum</span><span class="pun">(</span><span class="pln">numAry1</span><span class="pun">);</span></code></li><li class="L4"><code class="lang-javascript"><span class="pln">                    console</span><span class="pun">.</span><span class="pln">log</span><span class="pun">(</span><span class="pln">numAry2</span><span class="pun">);</span><span class="pln"> </span><span class="com">//numAry2就是'23';</span></code></li></ol></pre>
            </div>
            <div class="subPage-part-explain">
                <tt>
                    g.sum(Array);//获取数组中的总和<br />                   
                </tt>
            </div>
            <div class="subPage-part-explain">
                <div><b>测试方法</b></div>
                <div>
                    请输入对象字符串<b>[Array]</b>（对象中用JSON.parse(String)）
                </div>
                <div>
                    <textarea id="sumInput" class="InputTextarea">[3,2,6,4,8]</textarea>
                </div>
                <div> <input id="sumButton" type="button" value="执行   g.sum(Array)" /> </div>

                <div>
                    显示结果 
                </div>
                <div>
                    <textarea id="sumOutput" class="OutputTextarea"></textarea>
                </div>
                <script>
                    $("#sumButton").click(function () {
                        var numAry1 = JSON.parse($('#sumInput').val());
                        var numAry2 = g.sum(numAry1);
                        $('#sumOutput').val(numAry2);
                    });
                </script>
            </div>
        </div>

        <div id="avg" class="subPage-part">
            <div class="subPage-part-title"><span class="title-name">g.<strong>avg</strong> </span> <span class="title-type">Function(Array)</span> </div>
            <div class="subPage-part-code">
                <pre class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><code class="lang-javascript"></code></li><li class="L1"><code class="lang-javascript"><span class="pln">                  </span><span class="com">//*------数字数组中数值的平均值 --------*/ </span></code></li><li class="L2"><code class="lang-javascript"><span class="pln">                     </span><span class="com">//例如： </span></code></li><li class="L3"><code class="lang-javascript"><span class="pln">                    </span><span class="kwd">var</span><span class="pln"> numAry1 </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[</span><span class="lit">3</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</span><span class="pun">,</span><span class="pln"> </span><span class="lit">4</span><span class="pun">,</span><span class="pln"> </span><span class="lit">8</span><span class="pun">];</span></code></li><li class="L4"><code class="lang-javascript"><span class="pln">                    </span><span class="kwd">var</span><span class="pln"> numAry2 </span><span class="pun">=</span><span class="pln"> g</span><span class="pun">.</span><span class="pln">avg</span><span class="pun">(</span><span class="pln">numAry1</span><span class="pun">);</span></code></li><li class="L5"><code class="lang-javascript"><span class="pln">                    console</span><span class="pun">.</span><span class="pln">log</span><span class="pun">(</span><span class="pln">numAry2</span><span class="pun">);</span><span class="pln"> </span><span class="com">//numAry2就是'4.6';</span></code></li></ol></pre>
            </div>
            <div class="subPage-part-explain">
                <tt>
                    g.avg(Array)//获取数组中的平均数<br />                  
                </tt>
            </div>
            <div class="subPage-part-explain">
                <div><b>测试方法</b></div>
                <div>
                    请输入对象字符串<b>[Array]</b>（对象中用JSON.parse(String)）
                </div>
                <div>
                    <textarea id="avgInput" class="InputTextarea">[3,2,6,4,8]</textarea>
                </div>
                <div> <input id="avgButton" type="button" value="执行  g.avg(Array)" /> </div>

                <div>
                    显示结果 
                </div>
                <div>
                    <textarea id="avgOutput" class="OutputTextarea"></textarea>
                </div>
                <script>
                    $("#avgButton").click(function () {
                        var numAry1 = JSON.parse($('#avgInput').val());
                        var numAry2 = g.avg(numAry1);
                        $('#avgOutput').val(numAry2);
                    });
                </script>
            </div>
        </div>
        
        <div id="removeRepeatAttr" class="subPage-part">
            <div class="subPage-part-title"><span class="title-name">g.<strong>removeRepeatAttr</strong> </span> <span class="title-type">Function(Array)</span> </div>
            <div class="subPage-part-code">
                <pre class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><code class="lang-javascript"></code></li><li class="L1"><code class="lang-javascript"><span class="pln">                </span><span class="com">//*------去掉数组中重复的 --------*/ </span></code></li><li class="L2"><code class="lang-javascript"><span class="pln">                     </span><span class="com">//例如： </span></code></li><li class="L3"><code class="lang-javascript"><span class="pln">                    </span><span class="kwd">var</span><span class="pln"> numAry1 </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[</span><span class="lit">3</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">6</span><span class="pun">,</span><span class="pln"> </span><span class="lit">4</span><span class="pun">,</span><span class="pln"> </span><span class="lit">8</span><span class="pun">];</span></code></li><li class="L4"><code class="lang-javascript"><span class="pln">                    </span><span class="kwd">var</span><span class="pln"> numAry2 </span><span class="pun">=</span><span class="pln"> g</span><span class="pun">.</span><span class="pln">removeRepeatAttr</span><span class="pun">(</span><span class="pln">numAry1</span><span class="pun">);</span></code></li><li class="L5"><code class="lang-javascript"><span class="pln">                    console</span><span class="pun">.</span><span class="pln">log</span><span class="pun">(</span><span class="pln">numAry2</span><span class="pun">);</span><span class="com">//numAry2就是'[3,2,6,4,8]';</span></code></li></ol></pre>
            </div>
            <div class="subPage-part-explain">
                <tt>
                    g.removeRepeatAttr(Array)//去掉数组中重复的<br />                  
                </tt>
            </div>
            <div class="subPage-part-explain">
                <div><b>测试方法</b></div>
                <div>
                    请输入对象字符串<b>[Array]</b>（对象中用JSON.parse(String)）
                </div>
                <div>
                    <textarea id="removeRepeatAttrInput" class="InputTextarea">[3,2,6,4,6,8,2]</textarea>
                </div>
                <div> <input id="removeRepeatAttrButton" type="button" value="执行  g.removeRepeatAttr(Array)" /> </div>

                <div>
                    显示结果 （对象中用JSON.stringify(Array)）
                </div>
                <div>
                    <textarea id="removeRepeatAttrOutput" class="OutputTextarea"></textarea>
                </div>
                <script>
                    $("#removeRepeatAttrButton").click(function () {
                        var numAry1 = JSON.parse($('#removeRepeatAttrInput').val());
                        var numAry2 = g.removeRepeatAttr(numAry1);
                        $('#removeRepeatAttrOutput').val(JSON.stringify(numAry2));
                    });
                </script>
            </div>
        </div>


    </div>

</body>
</html>